import Data.List

primes :: [Integer]
primes = 2 : filter ( (==1) . length . primeFactors ) [3,5..]

primeFactors :: Integer -> [Integer]
primeFactors n = factor n primes
	where
	factor n (p:ps)
		| p*p > n		 = [n]
		| n `mod` p == 0 = p : factor ( n `div` p )	(p:ps)
		| otherwise		 = factor n ps

isPrime :: Integer -> Bool
isPrime n
	| n <= 1 	= False
	| otherwise =((length(primeFactors n)) == 1)
		
fourDigitPrimes = dropWhile (<999) $ takeWhile (	<10000) primes

list = nub [show a ++ show b ++ show c|a<-fourDigitPrimes,let perms = (map read.permutations.show) a, b<-perms, isPrime(b), a<b, let c = 2*b - a, isPrime c, c `elem` perms, c<9999 ] 

euler_049 = list !! 1